package com.wicket.okrframework.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wicket.okrframework.base.service.MHostTypeRecommendService;
import com.wicket.okrframework.base.service.dto.req.QueryHostTypeBizScnDetailReq;
import com.wicket.okrframework.base.service.dto.req.QueryHostTypeBizScnListReq;
import com.wicket.okrframework.common.dto.FieldInfo;
import com.wicket.okrframework.common.exception.BizException;
import com.wicket.okrframework.common.util.CommonFunctionHelper;
import com.wicket.okrframework.dal.mapper.mbg.HostTypeRecommendMapper;
import com.wicket.okrframework.dal.po.mbg.GradeScope;
import com.wicket.okrframework.dal.po.mbg.HostTypeRecommend;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;
import java.util.ArrayList;

/**
 * @author ：
 * @since 2022/1/19 15:39
 *
 *
 * @version 1.0
 */
@Service
public class MHostTypeRecommendServiceImpl
        extends ServiceImpl<HostTypeRecommendMapper, HostTypeRecommend>
        implements MHostTypeRecommendService {

    @Autowired
    HostTypeRecommendMapper hostTypeRecommendMapper;

    /**
   * 1-1-21查询宿主类型推荐到业务场景列表[1055]
   * gen by moon at 8/26/2022, 3:11:44 PM
   */
 @Trace(operationName = "1-1-21查询宿主类型推荐到业务场景列表")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  List<HostTypeRecommend>  queryHostTypeBizScnList(QueryHostTypeBizScnListReq reqDto) {
     
        try {
            QueryWrapper<HostTypeRecommend> queryWrapper = new QueryWrapper<>();
            reqDto.setIsValid("FALSE");
            
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(HostTypeRecommend.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(HostTypeRecommend.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper,likeList,fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap,likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(HostTypeRecommend.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);
            
            return ((List<HostTypeRecommend>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1",e,false);
        }
  }

    /**
   * 1-1-21修改宿主类型推荐的业务场景[1052]
   * gen by moon at 8/26/2022, 3:11:43 PM
   */
 @Trace(operationName = "1-1-21修改宿主类型推荐的业务场景")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  boolean  updateHostTypeBizScn(HostTypeRecommend hostTypeRecommend) {
     hostTypeRecommend.setOperationInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
hostTypeRecommend.setOperateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
if(hostTypeRecommend!=null && hostTypeRecommend.getSubjectLifeCycle()!=null &&  hostTypeRecommend.getSubjectLifeCycle().equals("CURRENTLY_VALID")) {
            hostTypeRecommend.setReleaseInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//RELEASED_CURRENT_INDUCTIONID
          }
if(hostTypeRecommend!=null && hostTypeRecommend.getSubjectLifeCycle()!=null && hostTypeRecommend.getSubjectLifeCycle().equals("ARCHIVING")) {
              hostTypeRecommend.setArchiveInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//ARCHIVE_CURRENT_INDUCTIONID
          }
if(hostTypeRecommend!=null && hostTypeRecommend.getSubjectLifeCycle()!=null && hostTypeRecommend.getSubjectLifeCycle().equals("CURRENTLY_VALID")){
             hostTypeRecommend.setReleaseTime(CommonFunctionHelper.getCurrentTime());//RELEASE_SYSTEM_CURRENT_TIME
            }
if(hostTypeRecommend!=null && hostTypeRecommend.getSubjectLifeCycle()!=null && hostTypeRecommend.getSubjectLifeCycle().equals("ARCHIVING")) {
              hostTypeRecommend.setArchiveTime(CommonFunctionHelper.getCurrentTime());//HISTORICAL_ARCHIVING
          }
        return super.updateById(hostTypeRecommend);
  }

    /**
   * 1-1-21新增宿主类型推荐到业务场景[1051]
   * gen by moon at 10/28/2022, 8:45:17 PM
   */
 @Trace(operationName = "1-1-21新增宿主类型推荐到业务场景")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  String  addHostTypeBizScn(HostTypeRecommend hostTypeRecommend) {
     hostTypeRecommend.setRecommendHostTypeRecordId(CommonFunctionHelper.getUid());//DISTRIBUTED_ID
hostTypeRecommend.setIsArchive("FALSE");
hostTypeRecommend.setOperationInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
hostTypeRecommend.setCreateInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
if(hostTypeRecommend!=null && hostTypeRecommend.getSubjectLifeCycle()!=null &&  hostTypeRecommend.getSubjectLifeCycle().equals("CURRENTLY_VALID")) {
            hostTypeRecommend.setReleaseInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//RELEASED_CURRENT_INDUCTIONID
          }
hostTypeRecommend.setOperateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
hostTypeRecommend.setCreateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
if(hostTypeRecommend!=null && hostTypeRecommend.getSubjectLifeCycle()!=null && hostTypeRecommend.getSubjectLifeCycle().equals("CURRENTLY_VALID")){
             hostTypeRecommend.setReleaseTime(CommonFunctionHelper.getCurrentTime());//RELEASE_SYSTEM_CURRENT_TIME
            }
hostTypeRecommend.setIsValid("FALSE");
hostTypeRecommend.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
hostTypeRecommend.setAppId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecAppId());//CURRENT_APPID
     if(super.save(hostTypeRecommend)){
        return hostTypeRecommend.getRecommendHostTypeRecordId();
     }else {
        return "-1";
     }
    
  }

    /**
   * 1-1-21查询宿主类型推荐的业务场景详情[1054]
   * gen by moon at 10/28/2022, 8:45:18 PM
   */
 @Trace(operationName = "1-1-21查询宿主类型推荐的业务场景详情")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  HostTypeRecommend  queryHostTypeBizScnDetail(QueryHostTypeBizScnDetailReq reqDto) {
     
        try {
         reqDto.setIsValid("FALSE");
            QueryWrapper<HostTypeRecommend> queryWrapper = new QueryWrapper<>();
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, new ArrayList<>());
            queryWrapper.orderByDesc("create_time");
            List<HostTypeRecommend> retList = super.list(queryWrapper);
            if(retList!=null && retList.size()>0){
                HostTypeRecommend retData = retList.get(0);

                return retData;
            }
            return null;
      } catch (Exception e) {
          e.printStackTrace();
          throw new BizException("-1",e,false);
      }
  }

    /**
   * 1-1-21删除宿主类型推荐到业务场景	[1053]
   * gen by moon at 8/26/2022, 3:11:43 PM
   */
 @Trace(operationName = "1-1-21删除宿主类型推荐到业务场景	")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  boolean  deleteHostTypeBizScn(String recommendHostTypeRecordId ) {
     
      return super.removeById(recommendHostTypeRecordId);
  }
}
